/**
 * 
 */
jQuery(function() {
        swapImages();
	jQuery("div#viewPortRightCell").hover(function(){
		jQuery(this).fadeTo( "slow" , 0.7);
		},function(){
		jQuery(this).fadeTo( "slow" , 1);
	}); 	
});


	

    
    

(function($) {
    $.fn.hoverIntent = function(handlerIn,handlerOut,selector) {

        // default configuration values
        var cfg = {
            interval: 100,
            sensitivity: 7,
            timeout: 0
        };

        if ( typeof handlerIn === "object" ) {
            cfg = $.extend(cfg, handlerIn );
        } else if ($.isFunction(handlerOut)) {
            cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector } );
        } else {
            cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut } );
        }

        // instantiate variables
        // cX, cY = current X and Y position of mouse, updated by mousemove event
        // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
        var cX, cY, pX, pY;

        // A private function for getting mouse position
        var track = function(ev) {
            cX = ev.pageX;
            cY = ev.pageY;
        };

        // A private function for comparing current and previous mouse position
        var compare = function(ev,ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            // compare mouse positions to see if they've crossed the threshold
            if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
                $(ob).off("mousemove.hoverIntent",track);
                // set hoverIntent state to true (so mouseOut can be called)
                ob.hoverIntent_s = 1;
                return cfg.over.apply(ob,[ev]);
            } else {
                // set previous coordinates for next time
                pX = cX; pY = cY;
                // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
                ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
            }
        };

        // A private function for delaying the mouseOut function
        var delay = function(ev,ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            ob.hoverIntent_s = 0;
            return cfg.out.apply(ob,[ev]);
        };

        // A private function for handling mouse 'hovering'
        var handleHover = function(e) {
            // copy objects to be passed into t (required for event object to be passed in IE)
            var ev = jQuery.extend({},e);
            var ob = this;

            // cancel hoverIntent timer if it exists
            if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

            // if e.type == "mouseenter"
            if (e.type == "mouseenter") {
                // set "previous" X and Y position based on initial entry point
                pX = ev.pageX; pY = ev.pageY;
                // update "current" X and Y position based on mousemove
                $(ob).on("mousemove.hoverIntent",track);
                // start polling interval (self-calling timeout) to compare mouse coordinates over time
                if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

                // else e.type == "mouseleave"
            } else {
                // unbind expensive mousemove event
                $(ob).off("mousemove.hoverIntent",track);
                // if hoverIntent state is true, then call the mouseOut function after the specified delay
                if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
            }
        };

        // listen for mouseenter and mouseleave
        return this.on({'mouseenter.hoverIntent':handleHover,'mouseleave.hoverIntent':handleHover}, cfg.selector);
    };
})(jQuery);


/**
 * 
 */

jQuery(function() {		
	/*	alert("Hello! I am an alert box!");	*/

	var config = {       
			sensitivity: 3,
			interval: 150,   
			over: function()
			{
				var subMenu = jQuery(this).children("ul");				
				subMenu.slideDown();
			},
			timeout: 10, 
			out: function()
			{
				var subMenu = jQuery(this).children("ul");
				subMenu.slideUp();			
			}
		};
	jQuery( ".liSub" ).hoverIntent(config);
});


/**
 * 
 */
   function swapImages(){
	   
           var html=[];
            html.push('<span class="show style_toptext"> ACHAT & VENTE <span>ALLEGER VOTRE DRESSING</span></span>');
            html.push('<span class="style_toptext"> RETOUR GRATUIT <span>SOUS 30 JOURS</span></span>');
            html.push('<span class="style_toptext"> SERVICE CLIENTS <span>09 00 00 00 00</span></span>');
            html.push('<span class="style_toptext"> CASHDRESSING.COM <span>LE LEADER EN IDF </span></span>');
            
           jQuery("#topCarousel").html(html.join(''));
           
	    var active = jQuery('.show'); 
	    var next = (jQuery('.show').next().length > 0) ? jQuery('.show').next() : jQuery('#topCarousel span:first');

	    active.fadeTo( "slow" , 0);
	    active.css( "display", "none" );
	    active.removeClass('show');
	    
	    next.fadeTo( "slow" , 1);
	    next.addClass('show');
	    
	    var activeIco = jQuery('.showIco'); 
	    var nextIco = (jQuery('.showIco').next().length > 0 && jQuery('.showIco').next().attr('id') != 'black') ? jQuery('.showIco').next() : jQuery('#topBar div#red');
	    
	    activeIco.removeClass('showIco');
	    activeIco.addClass('hideIco');
	    nextIco.removeClass('hideIco');
	    nextIco.addClass('showIco');
	}
	
	



/**
 * 
 */
jQuery(function() {
	jQuery( "#accordion" ).accordion({
		event: "click hoverintent",
		heightStyle: "auto"
	});
});
/*accordéon fermé au chargement de la page*/
jQuery(function() {
	jQuery( ".subAccordion" ).accordion(
	{
		collapsible: true,
		active: false
	 });
});
/*accordéon par défault*/
jQuery(function() {
	jQuery( ".subAccordionQ" ).accordion();
});

/*
 * 
* hoverIntent | Copyright 2011 Brian Cherne
* http://cherne.net/brian/resources/jquery.hoverIntent.html
* modified by the jQuery UI team
*/
jQuery.event.special.hoverintent = 
{	
	setup: function() 
	{
		jQuery( this ).bind( "mouseover", jQuery.event.special.hoverintent.handler );
	},
	teardown: function() 
	{
		jQuery( this ).unbind( "mouseover", jQuery.event.special.hoverintent.handler );
	},
	handler: function( event ) 
	{
		var currentX, currentY, timeout,
		args = arguments,
		target = jQuery( event.target ),
		previousX = event.pageX,
		previousY = event.pageY;
		function track( event ) 
		{
			currentX = event.pageX;
			currentY = event.pageY;
		};
		function clear() 
		{
			target
			.unbind( "mousemove", track )
			.unbind( "mouseout", clear );
			clearTimeout( timeout );
		}
		function handler() 
		{
			var prop,
			orig = event;
			if ( ( Math.abs( previousX - currentX ) +
			Math.abs( previousY - currentY ) ) < 7 ) 
			{
				clear();
				event = jQuery.Event( "hoverintent" );
				for ( prop in orig ) 
				{	
					if ( !( prop in event ) ) 
					{
						event[ prop ] = orig[ prop ];
					}
				}
	// Prevent accessing the original event since the new event
	// is fired asynchronously and the old event is no longer
	// usable (#6028)
				delete event.originalEvent;
				target.trigger( event );
			} 
			else 
			{
				previousX = currentX;
				previousY = currentY;
				timeout = setTimeout( handler, 100 );
			}
		}
		timeout = setTimeout( handler, 100 );
		target.bind(
		{
			mousemove: track,
			mouseout: clear
		});
	}
};



function launchAccueil(){
    
    jQuery(document).ready(function(){
 
        jQuery(window).scroll(function(){
            if (jQuery(this).scrollTop() > 400) {
                jQuery('.scrollup').fadeIn();
            } else {
                jQuery('.scrollup').fadeOut();
            }
        });
 
        jQuery('.scrollup').click(function(){
            jQuery("html, body").animate({ scrollTop: 0 }, 600);
            return false;
        });
        
        setInterval(swapImages, 2000);
        
    });
    
    
}


function step2(f, url){//passer de l'étape 1 à la 2 lors de la demande de sac!
            
            if (document.formvalidator.isValid(f)) {
       
                    window.location.href=url;
                    return true;
		} else {
			
			alert('Votre adresse n\'est pas valide');
                        return false;
		}
        }
    //Etape 2 commande de sac    
 function step22(url){//valide la demand de sac
     
     var bValid= true;
     
     if(jQuery("input[name=croix_rouge]:checked").val()!=='oui' && jQuery("input[name=croix_rouge]:checked").val()!=='non')
         bValid= false;
     
     if(jQuery("input[name=conditions_ventes]:checked").val()!=='lue' )
        bValid= false;
     if(jQuery("input[name=conditions_envoie]:checked").val()!=='vet')
        bValid= false;
     /*if(jQuery("input[name=conditions_marques]:checked").val()!=='marq')
         bValid= false;*/
     if(bValid===true){
         window.location.href=url;
     }else{
         alert("Vous devez cocher toutes les cases");
     }
     
 }
 
 
 
function enfantsNew(){
    
    jQuery.ajax({
        type:'post',
        url:'index.php?option=com_cashestimation&view=estimations&format=json&task=new_product&virtuemart_category_id=7',
        dataType:'JSON',
        success:function(data){
            displayProd("#display_new_enfant", data);
        }
    });
}

function bebesNew(){
    
    jQuery.ajax({
        type:'post',
        url:'index.php?option=com_cashestimation&view=estimations&format=json&task=new_product&virtuemart_category_id=9',
        dataType:'JSON',
        success:function(data){
            displayProd("#display_new_bebe", data);
        }
    });
}
